package com.mk.dao.response;

import java.io.Serializable;
import lombok.Data;

/**
 * @author XueJinCha
 */
@Data
public class Response<T> implements Serializable {

    public static final Integer COMMON_SUCCESS_CODE = 200;
    public static final Integer CODE_WAIT = 300;
    public static final Integer COMMON_ERROR_CODE = 900_000;
    private static final long serialVersionUID = -6132059700814514019L;

    private Integer code;

    private String message;

    private T payload;

    public Response() {
    }

    public Response(Integer code) {
        this.code = code;
    }

    public Response(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(Integer code, T payload) {
        this.code = code;
        this.payload = payload;
    }

    public Response(Integer code, String message, T payload) {
        this.code = code;
        this.message = message;
        this.payload = payload;
    }

    public Response(T payload) {
        this.code = COMMON_SUCCESS_CODE;
        this.payload = payload;
        this.message = "OK";
    }

    public static <T> Response<T> success() {
        return new Response<>(COMMON_SUCCESS_CODE);
    }

    public static <T> Response<T> success(T payload) {
        return new Response<>(payload);
    }

    public static <T> Response<T> success(String msg, T payload) {
        return new Response<>(COMMON_SUCCESS_CODE, msg, payload);
    }

    public static <T> Response<T> wait(String msg, T payload) {
        return new Response<>(CODE_WAIT, msg, payload);
    }

    public static <T> Response<T> success(String msg) {
        return new Response<>(COMMON_SUCCESS_CODE, msg);
    }

    public static <T> Response<T> success(Integer code, String msg, T payload) {
        return new Response<>(code, msg, payload);
    }

    public static <T> Response<T> fail(String msg) {
        return new Response<>(COMMON_ERROR_CODE, msg);
    }

    public static <T> Response<T> fail(Integer code, String msg) {
        return new Response<>(code, msg);
    }

    public static <T> Response<T> fail(Integer code, String msg, T payload) {
        return new Response<>(code, msg, payload);
    }
}
